//
//  HotView.m
//  News
//
//  Created by weige on 16/5/29.
//  Copyright © 2016年 weige. All rights reserved.
//

#import "HotView.h"
#import "HeadView.h"
#import "UIImageView+WebCache.h"
@interface HotView()
{
    //UIImageView *imgView;
    float viewW;
    float viewH;
    
}
@end
@implementation HotView
static float ViewSpancing=10;

- (instancetype)init
{
    self = [super init];
    if (self) {
        viewH=80;
      
        viewW=(SCREEN_WIDTH)/[HeadView loadDataIco:@"img"].count;
        //NSLog(@"%f",viewW);
        [self createHotView];
        // [HeadView loadDataIco:@"img"][0];
    }
    return self;
}
-(void)createHotView
{
   
    for (int i=0; i<[HeadView loadDataIco:@"img"].count; i++) {
        UIImageView *imgView=[[UIImageView alloc]init];
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imgClick:)];
        imgView.tag=i;
        imgView.userInteractionEnabled=YES;
        imgView.frame=CGRectMake(viewW*i, 0, viewW, 54);
        [imgView addGestureRecognizer:tap];
        [imgView sd_setImageWithURL:[NSURL URLWithString:[HeadView loadDataIco:@"img"][i]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            dispatch_async(dispatch_get_main_queue(), ^{
                imgView.image=image;
            });
            
        }];
        //显示
        [self addSubview:imgView];
    }
  
}

-(void)imgClick:(UITapGestureRecognizer *)sender
{
    
   // NSLog(@"%ld",[sender view].tag);
    NSDictionary *dic=[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:[sender view].tag] forKey:@"tag"];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"imgClickNote" object:nil userInfo:dic];
   // NSLog(@"%@",dic);
}

@end
